package com.yc.sole.financial.controller;

import com.yc.sole.financial.biz.PieceRateWageBiz;
import com.yc.sole.financial.request.PieceRateWageGroupQueryReq;
import com.yc.sole.financial.request.PieceRateWageDetailQueryReq;
import com.yc.sole.financial.request.PieceRateWageDetailReq;
import com.yc.sole.financial.response.PieceRateWageGroupResp;
import com.yc.sole.financial.response.PieceRateWageDetailResp;
import com.yc.sole.framework.mybatis.page.BaseBatchIdsReq;
import com.yc.sole.framework.mybatis.page.BasePageReq;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.framework.result.Result;
import com.yc.sole.framework.validate.DeleteGroup;
import com.yc.sole.framework.validate.SaveGroup;
import com.yc.sole.framework.validate.UpdateGroup;
import com.yc.sole.framework.web.PreAuth;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yizuomin
 * @date 2024-01-23
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
public class PieceRateWageController {

    private final PieceRateWageBiz pieceRateWageBiz;

    /**
     * 通过Id修改
     *
     * @param pieceRateWageReq
     * @return RestResult
     */
    @PreAuth(value = "financial:pieceRateWage:update", description = "修改")
    @PostMapping("/api/financial/pieceRateWage/updatePieceRateWageDetailById")
    public Result<Void> updatePieceRateWageDetailById(@RequestBody @Validated(UpdateGroup.class) PieceRateWageDetailReq pieceRateWageReq) {
        pieceRateWageBiz.updatePieceRateWageDetailById(pieceRateWageReq);
        return Result.success();
    }

    /**
     * 通过Id修改
     *
     * @param pieceRateWageReq
     * @return RestResult
     */
    @PreAuth(value = "financial:pieceRateWage:update", description = "计算工资")
    @PostMapping("/api/financial/pieceRateWage/calculatePieceRateWage")
    public Result<Void> calculatePieceRateWage(@RequestBody @Validated(SaveGroup.class) PieceRateWageDetailReq pieceRateWageReq) {
        pieceRateWageBiz.calculatePieceRateWage(pieceRateWageReq);
        return Result.success();
    }

    /**
     * 通过id批量删除
     *
     * @param baseDeleteReq
     * @return RestResult
     */
    @PreAuth(value = "financial:pieceRateWage:delete", description = "删除")
    @PostMapping("/api/financial/pieceRateWage/deletePieceRateWageDetail")
    public Result<Void> deletePieceRateWageDetailByIds(@RequestBody @Validated(DeleteGroup.class) BaseBatchIdsReq baseDeleteReq) {
        pieceRateWageBiz.deletePieceRateWageDetailByIds(baseDeleteReq.getIds());
        return Result.success();
    }

    /**
     * 通过id批量删除分组
     *
     * @param baseDeleteReq
     * @return RestResult
     */
    @PreAuth(value = "financial:pieceRateWage:delete", description = "删除")
    @PostMapping("/api/financial/pieceRateWage/deletePieceRateWageGroup")
    public Result<Void> deletePieceRateWageGroup(@RequestBody @Validated(DeleteGroup.class) BaseBatchIdsReq baseDeleteReq) {
        pieceRateWageBiz.deletePieceRateWageGroup(baseDeleteReq.getIds());
        return Result.success();
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return Result
     */
    @PreAuth(value = "financial:pieceRateWage:select", description = "查询")
    @PostMapping("/api/financial/pieceRateWage/selectPieceRateWageDetailById/{id}")
    public Result<PieceRateWageDetailResp> selectPieceRateWageById(@PathVariable Long id) {
        return Result.data(pieceRateWageBiz.selectPieceRateWageById(id));
    }

    /**
     * 分页查询明细
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "financial:pieceRateWage:select", description = "分页查询明细")
    @PostMapping("/api/financial/pieceRateWage/selectDetailPage")
    public Result<Paging<PieceRateWageDetailResp>> selectDetailPage(@RequestBody @Validated BasePageReq<PieceRateWageDetailQueryReq> basePageReq) {
        return Result.data(pieceRateWageBiz.selectDetailPage(basePageReq.toPage(), basePageReq.getQuery()));
    }

    /**
     * 分页查询分组
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "financial:pieceRateWage:select", description = "分页查询分组")
    @PostMapping("/api/financial/pieceRateWage/selectGroupPage")
    public Result<Paging<PieceRateWageGroupResp>> selectGroupPage(@RequestBody @Validated BasePageReq<PieceRateWageGroupQueryReq> basePageReq) {
        return Result.data(pieceRateWageBiz.selectGroupPage(basePageReq.toPage(), basePageReq.getQuery()));
    }
}
